package com.java.base.propertydescriptor;

import org.springframework.beans.BeanUtils;
import org.springframework.core.MethodParameter;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @ClassName: Main
 * @Author: suncx
 * @CreateDate: 2020-04-12 13:28
 * @Description:
 */
public class Main {
    public static void main(String[] args) {
        try {
            Class clazz = Class.forName("com.java.base.propertydescriptor.Price");
            Object obj =  clazz.newInstance();
            Field[] fields = clazz.getDeclaredFields();
            //写数据，即获得写方法（setter方法）给属性赋值
            for(Field f : fields){
                PropertyDescriptor pd = new PropertyDescriptor(f.getName(),clazz);
                Method method = pd.getWriteMethod();
                method.invoke(obj,"100元");
            }
            System.out.println(obj.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
